<template>
  <div class="container-arsbtlist">
    <div v-if="sbtlist">
      <div v-if="isOpera>0">
        <el-button type="success" @click="onChangeOpera(2)" v-show="isOpera==1">编辑</el-button>
        <el-button type="danger" @click="onChangeOpera(1)" v-show="isOpera==2">取消</el-button>
      </div>
      <div class="sbt-groud" v-if="sbtlist.wanneng.length">
        <div class="card-title">万能识别图</div>
        <div
          v-for="(item,index) in sbtlist.wanneng"
          :key="index"
          class="card"
          :style="` width: calc(100% / ${cardRowNum} - 30px);`"
          v-if="item.type==1"
          @click="activeImg(item)"
        >
          <div style="overflow: hidden;">
            <img :src="item.image" alt="">
            <div class="card-footer">
              {{ item.detail }}
            </div>
          </div>

          <div class="card-del" v-show="isOpera==2" @click="delImg(item)">
            x
          </div>
        </div>
      </div>
      <div class="sbt-groud" v-if="sbtlist.putong.length">
        <div class="card-title">普通识别图</div>
        <div
          v-for="(item,index) in sbtlist.putong"
          :key="index"
          class="card"
          :style="` width: calc(100% / ${cardRowNum} - 30px);`"
          v-if="item.type!=1"
          @click="activeImg(item)"
        >
          <div style="overflow: hidden;">
            <img :src="item.image" alt="">
            <div class="card-footer">
              {{ item.detail }}
            </div>
          </div>

          <div class="card-del" v-show="isOpera==2" @click="delImg(item)">
            x
          </div>
        </div>
      </div>
    </div>
    <div v-else>
      暂无识别图
    </div>
  </div>
</template>
<script>
import sbtApi from '@/api/sbtApi'
export default {
  name: 'Arsbtlist',
  inject: [
    'reload'
  ],
  // 组件组件
  components: {},
  // 视图层要渲染的数据
  data() {
    return {
      sbtlist: {
        wanneng:[],
        putong:[]
      },
      cardRowNum: 6,
      isOpera:0
    }
  },
  // 页面创建前
  beforeCreate() {
  },
  // 页面创建完成时
  created() {
    if (this.$attrs.cardRowNum) {
      this.cardRowNum = this.$attrs.cardRowNum
    }
    this.isOpera=this.$route.path.indexOf('arsbt/arsbtlist')!==-1?1:0
    sbtApi.getAllSbt().then(reslut => {
      let list = reslut;
      for(let item of list){
        if (item.type==1){
          this.sbtlist.wanneng = [...this.sbtlist.wanneng,item]
        }else{
          this.sbtlist.putong = [...this.sbtlist.putong,item]
        }
      }
      // this.sbtlist = reslut
    })
  },
  // 页面渲染完成时
  mounted() {

  },

  // 自定义函数部分
  methods: {
    activeImg(item) {

      this.$emit('sbtInfo', item)
    },
    onChangeOpera(e){
      this.isOpera = e
    },
    delImg(item){
      sbtApi.deleteSbt(item.id,item.targetId).then(ress => {
        this.reload()
      })
    }
  }
}
</script>
<style scoped lang="scss" >
.container-arsbtlist {
  padding: 30px;
  padding-top: 0;
  .sbt-groud{
    display: block;
    overflow: hidden;
    margin-right: -30px;
  }
  .card-title{
    font-size: 20px;
    font-weight: bold;
    padding-top: 30px;
  }
  .card{
    margin-top: 30px;

    float: left;
    border: 1px solid #dddddd;
    margin-right: 30px;
    transition:0.2s;
    position: relative;
    &:hover{
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    }
    img{
      height: 200px;
      border-bottom: 1px solid #dddddd;
    }
    .card-footer{
      border-top: 1px solid #dddddd;
      height: 60px;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .card-del{
      position: absolute;
      background-color: red;
      border-radius: 50%;
      width: 28px;
      height: 28px;
      right: -14px;
      top: -14px;
      text-align: center;
      line-height: 28px;
      font-size: 18px;
      color: #fff;
    }
  }

}
</style>

